package com.yxkj.syh.app.huarong.activities.account.login.pwd;

import android.content.Context;
import android.os.Bundle;

import com.alibaba.android.arouter.launcher.ARouter;
import com.syh.app.basic.base.BaseFragment;
import com.syh.app.basic.config.BasicConstants;
import com.yxkj.syh.app.huarong.BR;
import com.yxkj.syh.app.huarong.R;
import com.yxkj.syh.app.huarong.constants.ArouterPath;
import com.yxkj.syh.app.huarong.databinding.FragmentPwdLoginBinding;

/**
 * 账号密码登录
 */
public class PwdLoginFragment extends BaseFragment<FragmentPwdLoginBinding, PwdLoginVM> {


    public PwdLoginFragment() {
        // Required empty public constructor
    }

    public static PwdLoginFragment newInstance() {
        PwdLoginFragment fragment = new PwdLoginFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    protected int getViewModelId() {
        return BR.pwdLoginVM;
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_pwd_login;
    }

    @Override
    protected void initView() {
        mVDBinding.ivEyes.setOnClickListener(v -> {
            if (mViewModel.ofEyesOpen.get()) {
                mViewModel.ofEyesOpen.set(false);
                mVDBinding.ivEyes.setImageResource(R.mipmap.ic_close_eyes);
                mVDBinding.etPwd.setInputType(0x81);
            } else {
                mViewModel.ofEyesOpen.set(true);
                mVDBinding.ivEyes.setImageResource(R.mipmap.ic_open_eyes);
                mVDBinding.etPwd.setInputType(0x90);
            }
            if (mVDBinding.etPwd.isFocused()){
                mVDBinding.etPwd.setSelection(mVDBinding.etPwd.getText().length());
            }
        });

        mVDBinding.tvUserAgreement.setOnClickListener(v -> {
            ARouter.getInstance().build(ArouterPath.WEB_ACTIVITY)
                    .withString("title", "")
                    .withString("link", BasicConstants.USER_AGREEMENT_URL)
                    .navigation();
        });

        mVDBinding.tvPrivacyClause.setOnClickListener(v -> {
            ARouter.getInstance().build(ArouterPath.WEB_ACTIVITY)
                    .withString("title", "")
                    .withString("link", BasicConstants.PRIVACY_CLAUSE_URL)
                    .navigation();
        });
    }
}
